package com.chendechao.model_home.ui.recommend

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.chendechao.model_home.databinding.LayoutCommentBinding
import com.chendechao.model_home.model.CommentData
import com.chendechao.model_home.ui.recommend.RecommendAdapter.DiffCallback

class CommentAdapter : ListAdapter<CommentData, CommentAdapter.CommentViewHolder>(DiffCallback()) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommentViewHolder {
        val inflater = LayoutInflater.from(parent.context)
        val binding = LayoutCommentBinding.inflate(inflater, parent, false)
        return CommentViewHolder(binding)
    }

    override fun onBindViewHolder(holder: CommentViewHolder, position: Int) {
        val item = getItem(position)
        holder.bind(item)
    }

    class CommentViewHolder(private val binding: LayoutCommentBinding) :
        RecyclerView.ViewHolder(binding.root) {

        fun bind(item: CommentData) {
            // 在这里绑定数据到视图
            // 例如：binding.videoTitle.text = item.title
            binding.commentTitle.text = item.nickname
            binding.commentTime.text = item.createtime



        }
    }

    class DiffCallback : DiffUtil.ItemCallback<CommentData>() {
        override fun areItemsTheSame(
            oldItem: CommentData,
            newItem: CommentData
        ): Boolean {
            return   oldItem == newItem
        }

        override fun areContentsTheSame(
            oldItem: CommentData,
            newItem: CommentData
        ): Boolean {
            return   oldItem == newItem
        }

    }
}